
#include "MSP430G2553.h"

void Init_ADC();
void Init_SPI();

unsigned int adc_sensor;
char temp;

int main( void )
{
	// Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
        
  Init_ADC();
  Init_SPI();
  _BIS_SR(GIE);  
  while(1)
  {
     ADC10CTL0 |= ENC + ADC10SC;
     //__delay_cycles(100);
     //adc_sensor = ADC10MEM;
     temp=((ADC10MEM - 675) * 422) / 1024;
     IE2 |= UCA0RXIE;                          // Enable USCI0 RX interrupt
  }
}


//======================================================

void Init_ADC()
{
  ADC10CTL1 |= INCH_10 + ADC10DIV_3;         
  ADC10CTL0 |= SREF_1 + ADC10SHT_3 + REFON + ADC10ON;	
}
//======================================================

void Init_SPI()
{
  P1DIR &= ~0x20;
  P1SEL = BIT1 + BIT2 + BIT4 + BIT5;
  P1SEL2 = BIT1 + BIT2 + BIT4 + BIT5;
  UCA0CTL1 = UCSWRST;                       // **Put state machine in reset**
  UCA0CTL0 |=   UCCKPL +   UCSYNC ;      // 3-pin, 8-bit SPI master
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  IE2 |= UCA0RXIE;                          // Enable USCI0 RX interrupt
}
//======================================================
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR (void)
{
  while (!(IFG2 & UCA0TXIFG));              // USCI_A0 TX buffer ready?
  UCA0TXBUF = temp ;
    IE2 &= ~UCA0RXIE;
}